package com.huangsm.concurrentbook;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;

/**
 * 测试CompletionService，将Executor和BlockingQueue功能合并
 * @author huang
 * @date 2019/3/1
 */
public class CompletionServiceTest {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ExecutorService pool = Executors.newFixedThreadPool(10);
        CompletionService completionService=new ExecutorCompletionService<Integer>(pool);
        Future<Integer> future = (Future<Integer>) pool.submit(() -> {
            int num = 0;
            for (int i = 0; i < 10; i++) {
                num += i;
            }
        });
       Future take = completionService.take();
        Object o = take.get();
        System.out.println(o);
    }
}

